﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LDTB.Service;

namespace LDTB
{
    public partial class VillageEdit : Form
    {
        LDTBDataDataContext ds = DataService.DB;
        int id;
        public VillageEdit()
        {
            InitializeComponent();
        }
        public VillageEdit(int id_)
        {
            InitializeComponent();
            id = id_;



        }

        private void button1_Click(object sender, EventArgs e)
        {
            var village = (from v in ds.Villages
                           where v.VillageID == id
                           select v).FirstOrDefault();

            village.VillageName = this.txtVillageName.Text;

            village.WardID = int.Parse(ddlWard.SelectedValue.ToString());

            ds.SubmitChanges();
        }

        private void VillageEdit_Load(object sender, EventArgs e)
        {

            List<Ward> list = new List<Ward>();

            list.AddRange(from w in ds.Wards select w);

            ddlWard.DataSource = list;
            ddlWard.DisplayMember = "WardName";
            ddlWard.ValueMember = "ID";


            //thiet lap txext

            var x = (from vill in ds.Villages
                     where vill.VillageID == id
                     select vill).FirstOrDefault();

            this.txtVillageName.Text = x.VillageName;
                       
            ddlWard.SelectedValue = x.WardID.Value;

        }
    }
}
